﻿using Application.MainModule.CustomerServiceManagement;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Domain.MainModule.CustomerServices;
using Domain.MainModule.Entities;
using System.Collections.Generic;
using Infraestructure.CrossCutting.IoC;

namespace Application.MainModule.Tests
{
    ///<summary>
    ///This is a test class for CustomerServiceManagementServiceTest and is intended
    ///to contain all CustomerServiceManagementServiceTest Unit Tests
    ///</summary>
    [TestClass()]
    public class CustomerServiceManagementServiceTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        /// <summary>
        ///A test for AddCustomerService
        ///</summary>
        [TestMethod()]
        public void AddCustomerService_Invoke_Test()
        {
            //Arrange
            ICustomerServiceManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<ICustomerServiceManagementService>();
            Guid customerServiceId = Guid.Parse("ABCDF456-2522-AABB-AAFF-AAAACCBBBBBB");
            CustomerService customerService = new CustomerService()
            {
                CustomerServiceId = customerServiceId
            };
            CustomerService result = null;

            //Act
            target.AddCustomerService(customerService);

            //Assert
            result = target.FindCustomerServiceById(customerServiceId);
            Assert.IsNotNull(result);
            Assert.AreEqual(customerServiceId, result.CustomerServiceId);
            target.RemoveCustomerService(result);
        }

        /// <summary>
        ///A test for ChangeCustomerService
        ///</summary>
        [TestMethod()]
        public void ChangeCustomerService_Invoke_Test()
        {
            //Arrange
            ICustomerServiceManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<ICustomerServiceManagementService>();
            Guid customerServiceId = Guid.Parse("ABCDF456-2222-AABB-AAFF-AAAACCBBBBBB");
 
            //Act
            CustomerService customerService = target.FindCustomerServiceById(customerServiceId);
            string oldValue = customerService.Description;
            customerService.Description = "new description";
            target.ChangeCustomerService(customerService);
            CustomerService result = target.FindCustomerServiceById(customerServiceId);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreNotEqual(oldValue, result.Description);
        }

        /// <summary>
        ///A test for FindCustomerServiceById
        ///</summary>
        [TestMethod()]
        public void FindCustomerServiceById_Invoke_Test()
        {
            //Arrange
            ICustomerServiceManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<ICustomerServiceManagementService>();
            Guid customerServiceId = Guid.Parse("ABCDF456-2222-AABB-AAFF-AAAACCBBBBBB");
            CustomerService actual;

            //Act
            actual = target.FindCustomerServiceById(customerServiceId);

            //Assert
            Assert.IsNotNull(actual);
            Assert.AreEqual(customerServiceId, actual.CustomerServiceId);
        }
		
		        /// <summary>
        ///A test for FindCustomerServiceByOrderId
        ///</summary>
        [TestMethod()]
        public void FindCustomerServiceByOrderId_Invoke_Test()
        {
            //Arrange
            ICustomerServiceManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<ICustomerServiceManagementService>();
            Guid orderId = Guid.Parse("ABCDF456-3222-AABB-AAFF-AAAACCBBBBBB");

            //Act
            List<CustomerService> actual;
            actual = target.FindCustomerServiceByOrderId(orderId);

            //Assert
            Assert.IsNotNull(actual);
            Assert.AreEqual(1, actual.Count);
            Assert.AreEqual(orderId, actual[0].OrderId);
        }

        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void RemoveCustomerService_Invoke_NullItemThrowNewArgumentNullException_Test()
        {
            //Arrange
            ICustomerServiceManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<ICustomerServiceManagementService>();

            //Act
            target.RemoveCustomerService(null);
        }

        /// <summary>
        ///A test for RemoveCustomerService
        ///</summary>
        [TestMethod()]
        public void RemoveCustomerService_Invoke_Test()
        {
            //Arrange
            ICustomerServiceManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<ICustomerServiceManagementService>();
            CustomerService customerService = null;

            //Act
            customerService = target.FindCustomerServiceById(Guid.Parse("ABCDF456-2222-AABB-AAFF-AAAACCBBBBBB"));
            target.RemoveCustomerService(customerService);

            //Assert
            CustomerService result = target.FindCustomerServiceById(Guid.Parse("ABCDF456-2222-AABB-AAFF-AAAACCBBBBBB"));
            Assert.IsNull(result);
            customerService = new CustomerService()
                    {
                        CustomerServiceId = Guid.Parse("ABCDF456-2222-AABB-AAFF-AAAACCBBBBBB"),
                        Description = "description 01",
                        OrderId = Guid.Parse("ABCDF456-1222-AABB-AAFF-AAAACCBBBBBB")
                    };
            target.AddCustomerService(customerService);
        }
    }
}
